package com.xiangban.xiangbanmall.controller;

import com.xiangban.xiangbanmall.aop.Permission;
import com.xiangban.xiangbanmall.model.TUser;
import com.xiangban.xiangbanmall.model.TUserMember;
import com.xiangban.xiangbanmall.model.TUserMemberGrade;
import com.xiangban.xiangbanmall.model.TUserWalletRecord;
import com.xiangban.xiangbanmall.model.dto.UserMember;
import com.xiangban.xiangbanmall.model.res.ApiResult;
import com.xiangban.xiangbanmall.service.UserMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/11/1 16:37
 */
@RestController
@RequestMapping("/api/mall/user_member")
@Api(tags = "会员信息管理")
public class UserMemberController {

    @Autowired
    private UserMemberService userMemberService;

    @RequestMapping("/open_user_member")
    @ApiOperation("会员开通")
    @Permission
    public ApiResult<Object> openUserMember(@RequestBody UserMember userMember){
        return ApiResult.newSuccess(userMemberService.openUserMember(userMember));
    }

    @RequestMapping("/add_user_money")
    @ApiOperation("会员充值")
    @Permission
    public ApiResult<Object> addUserMoney(@RequestBody UserMember userMember){
        return ApiResult.newSuccess(userMemberService.addUserMoney(userMember));
    }

    @RequestMapping("/insert_user_money")
    @ApiOperation("增加用户余额")
    @Permission
    public ApiResult<Object> insertUserMoney(@RequestBody TUserMember userMember){
        userMemberService.insertUserMoney(userMember);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/insert_user_integral")
    @ApiOperation("增加用户积分")
    @Permission
    public ApiResult<Object> insertUserIntegral(@RequestBody TUserMember userMember){
        userMemberService.insertUserIntegral(userMember);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/update_user_money")
    @ApiOperation("扣除用户金额")
    @Permission
    public ApiResult<Object> updateUserMoney(@RequestBody UserMember userMember){
        userMemberService.updateUserMoney(userMember);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/get_recharge_record")
    @ApiOperation("充值记录")
    @Permission
    public ApiResult<Object> getRechargeRecord(){
        return ApiResult.newSuccess(userMemberService.getRechargeRecord());
    }

    @RequestMapping("/get_member_grade_id")
    @ApiOperation("会员权益")
    @Permission
    public ApiResult<Object> getMemberGradeId(@RequestBody TUserMemberGrade userMemberGrade){
        return ApiResult.newSuccess(userMemberService.getMemberGradeId(userMemberGrade));
    }

    @RequestMapping("/get_member_grade_id_info")
    @ApiOperation("各会员等级信息")
//    @Permission
    public ApiResult<Object> getMemberGradeIdInfo(){
        return ApiResult.newSuccess(userMemberService.getMemberGradeIdInfo());
    }

    @RequestMapping("/withdraw")
    @ApiOperation("提现")
    @Permission
    public ApiResult<Object> withdraw(@RequestBody HashMap<String, String> map){
        userMemberService.withdraw(map);
        return ApiResult.newSuccess();
    }
}
